<template>
  <view class="">
    <titleXX :parentTitle="title"></titleXX>
    <view style="margin: 20px auto; text-align: center">支付密码</view>
    <view class="item" @tap="KeyboarOpen">
      <password-input :numLng="password"></password-input>
    </view>
    <number-keyboard tabBar ref="KeyboarHid" @input="onInput" psdLength="6"></number-keyboard>
    <u-toast ref="uToast"></u-toast>
  </view>
</template>

<script>
import titleXX from "@/components/title.vue"
import { getAccessToken } from "@/common/YYSLxx.js"
import moment from "moment"
import numberKeyboard from "@/components/number-keyboard/number-keyboard.vue"
import passwordInput from "@/components/password-input/password-input.vue"
export default {
  components: {
    titleXX,
    numberKeyboard,
    passwordInput
  },
  onLoad(options) {
    //因为此时实例没有挂载完成，需要延迟操作
    setTimeout(() => {
      this.$refs.KeyboarHid.open()
    }, 50)
    this.goodList = options.list
  },
  data() {
    return {
      title: "输入密码",
      number: "123456",
      password: "",
      goodList: []
    }
  },
  methods: {
    KeyboarOpen(e) {
      this.$refs.KeyboarHid.open()
    },
    //输入的值
    onInput(val) {
      this.password = val
      if (val.length == 6 && val == this.number) {
        this.$refs.KeyboarHid.close()
        this.$refs.uToast.show({
          type: "success",
          message: "支付成功"
        })
        this.calendar(this.goodList)
      } else if (val.length == 6 && val != this.number) {
        this.$refs.uToast.show({
          type: "error",
          message: "密码错误"
        })
      }
    },
    calendar(item) {
      const currentTimeStamp = moment().unix();
				const min = BigInt('1' + '0'.repeat(18)); // 10^18
				const max = BigInt('1' + '0'.repeat(19)); // 10^19
				const randomNum = min + BigInt(Math.floor(Math.random() * Number(max - min)));
				let itemXX = {
					SBBT: "文创产品",
					orderNumber: currentTimeStamp + randomNum.toString(), //预约编号
					siteId: uni.getStorageSync('siteData').id,
					goodInfo: [{
						id: item[0].id,
						requestQty: 1
					}],
					orderProject: "文创产品", //预约项目
					orderProjectType: "1", //0:   1:  (区分健康自测类型与其他类型)
					orderCreationTime: moment().format("YYYY-MM-DD"), //下单时间
					estimateArrivalTime: "", //预计上门时间
					estimateSumPrice: "", //预估费用
					orderSubType: "文创产品", //预约类型
					serviceDescription: "", //服务介绍
					orderLocation: "", //预约地址(非空展示)
					serviceTip: "", //温馨提示(非空展示)
					goodSumPrice: "", //总价
					serviceTitleList: ["", "", "", ""], //服务标题
					goodList: [{
						goodId: item[0].goodId,
						goodName: "",
						servicePrice: "",
						serviceQty: "",
						goodCountPrice: "",
						serviceProjectName: item[0].goodName,
						serviceProjectNameTitle: "物品名称：",
						remark: item[0].goodDescription,
						remarkTitle: "物品描述：",
						serviceMessage: item[0].remark,
						serviceMessageTitle: "领取地点："
					}],
				}
      getAccessToken(itemXX, "文创产品")
    }
  }
}
</script>

<style>
.main {
  padding: 0rpx 40rpx;
}
.ipt {
  border-bottom: 1rpx solid #cccccc;
}
.item {
  padding: 10rpx 0rpx;
}
.title {
  margin: 30rpx 0;
}
</style>
